﻿using System;
using System.Data;
using System.Text;
using System.Data.SQLite;

namespace Clipper.DAL
{
	/// <summary>
	/// 数据访问类:StandardInfo
	/// </summary>
	public partial class StandardInfo
	{
		public StandardInfo()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return SQLiteHelper.GetMaxID("standardInfoID", "StandardInfo"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int standardInfoID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from StandardInfo");
			strSql.Append(" where standardInfoID=@standardInfoID ");
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@standardInfoID", DbType.Int32,4)			};
			parameters[0].Value = standardInfoID;

			return SQLiteHelper.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Clipper.Model.StandardInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into StandardInfo(");
			strSql.Append("standardInfoID,DetectItem,standardAmount,LightChromeRelativity,standardLight1,standardLight2,standardLight3,standardLight4,standardLight5,standardLight6,standardLight7,standardChrome1,standardChrome2,standardChrome3,standardChrome4,standardChrome5,standardChrome6,standardChrome7,adjustLight1,adjustLight2,adjustChrome1,adjustChrome2)");
			strSql.Append(" values (");
			strSql.Append("@standardInfoID,@DetectItem,@standardAmount,@LightChromeRelativity,@standardLight1,@standardLight2,@standardLight3,@standardLight4,@standardLight5,@standardLight6,@standardLight7,@standardChrome1,@standardChrome2,@standardChrome3,@standardChrome4,@standardChrome5,@standardChrome6,@standardChrome7,@adjustLight1,@adjustLight2,@adjustChrome1,@adjustChrome2,@StandardDate)");
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@standardInfoID", DbType.Int32,4),
					new SQLiteParameter("@DetectItem", DbType.String,20),
					new SQLiteParameter("@standardAmount", DbType.Byte,1),
					new SQLiteParameter("@LightChromeRelativity", DbType.Byte,1),
					new SQLiteParameter("@standardLight1", DbType.Decimal,8),
					new SQLiteParameter("@standardLight2", DbType.Decimal,8),
					new SQLiteParameter("@standardLight3", DbType.Decimal,8),
					new SQLiteParameter("@standardLight4", DbType.Decimal,8),
					new SQLiteParameter("@standardLight5", DbType.Decimal,8),
					new SQLiteParameter("@standardLight6", DbType.Decimal,8),
					new SQLiteParameter("@standardLight7", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome1", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome2", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome3", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome4", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome5", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome6", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome7", DbType.Decimal,8),
					new SQLiteParameter("@adjustLight1", DbType.Decimal,8),
					new SQLiteParameter("@adjustLight2", DbType.Decimal,8),
					new SQLiteParameter("@adjustChrome1", DbType.Decimal,8),
					new SQLiteParameter("@adjustChrome2", DbType.Decimal,8),
                    new SQLiteParameter("@StandardDate",DbType.DateTime),};
			parameters[0].Value = model.standardInfoID;
			parameters[1].Value = model.DetectItem;
			parameters[2].Value = model.standardAmount;
			parameters[3].Value = model.LightChromeRelativity;
			parameters[4].Value = model.standardLight1;
			parameters[5].Value = model.standardLight2;
			parameters[6].Value = model.standardLight3;
			parameters[7].Value = model.standardLight4;
			parameters[8].Value = model.standardLight5;
			parameters[9].Value = model.standardLight6;
			parameters[10].Value = model.standardLight7;
			parameters[11].Value = model.standardChrome1;
			parameters[12].Value = model.standardChrome2;
			parameters[13].Value = model.standardChrome3;
			parameters[14].Value = model.standardChrome4;
			parameters[15].Value = model.standardChrome5;
			parameters[16].Value = model.standardChrome6;
			parameters[17].Value = model.standardChrome7;
			parameters[18].Value = model.adjustLight1;
			parameters[19].Value = model.adjustLight2;
			parameters[20].Value = model.adjustChrome1;
			parameters[21].Value = model.adjustChrome2;
            parameters[22].Value = model.StandardDate;
			int rows=SQLiteHelper.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Clipper.Model.StandardInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update StandardInfo set ");
			strSql.Append("DetectItem=@DetectItem,");
			strSql.Append("standardAmount=@standardAmount,");
			strSql.Append("LightChromeRelativity=@LightChromeRelativity,");
			strSql.Append("standardLight1=@standardLight1,");
			strSql.Append("standardLight2=@standardLight2,");
			strSql.Append("standardLight3=@standardLight3,");
			strSql.Append("standardLight4=@standardLight4,");
			strSql.Append("standardLight5=@standardLight5,");
			strSql.Append("standardLight6=@standardLight6,");
			strSql.Append("standardLight7=@standardLight7,");
			strSql.Append("standardChrome1=@standardChrome1,");
			strSql.Append("standardChrome2=@standardChrome2,");
			strSql.Append("standardChrome3=@standardChrome3,");
			strSql.Append("standardChrome4=@standardChrome4,");
			strSql.Append("standardChrome5=@standardChrome5,");
			strSql.Append("standardChrome6=@standardChrome6,");
			strSql.Append("standardChrome7=@standardChrome7,");
			strSql.Append("adjustLight1=@adjustLight1,");
			strSql.Append("adjustLight2=@adjustLight2,");
			strSql.Append("adjustChrome1=@adjustChrome1,");
			strSql.Append("adjustChrome2=@adjustChrome2,");
            strSql.Append("StandardDate=@StandardDate");
			strSql.Append(" where standardInfoID=@standardInfoID ");
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@DetectItem", DbType.String,20),
					new SQLiteParameter("@standardAmount", DbType.Byte,1),
					new SQLiteParameter("@LightChromeRelativity", DbType.Byte,1),
					new SQLiteParameter("@standardLight1", DbType.Decimal,8),
					new SQLiteParameter("@standardLight2", DbType.Decimal,8),
					new SQLiteParameter("@standardLight3", DbType.Decimal,8),
					new SQLiteParameter("@standardLight4", DbType.Decimal,8),
					new SQLiteParameter("@standardLight5", DbType.Decimal,8),
					new SQLiteParameter("@standardLight6", DbType.Decimal,8),
					new SQLiteParameter("@standardLight7", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome1", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome2", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome3", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome4", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome5", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome6", DbType.Decimal,8),
					new SQLiteParameter("@standardChrome7", DbType.Decimal,8),
					new SQLiteParameter("@adjustLight1", DbType.Decimal,8),
					new SQLiteParameter("@adjustLight2", DbType.Decimal,8),
					new SQLiteParameter("@adjustChrome1", DbType.Decimal,8),
					new SQLiteParameter("@adjustChrome2", DbType.Decimal,8),
					new SQLiteParameter("@standardInfoID", DbType.Int32,4),
                    new SQLiteParameter("@StandardDate",DbType.DateTime)};
			parameters[0].Value = model.DetectItem;
			parameters[1].Value = model.standardAmount;
			parameters[2].Value = model.LightChromeRelativity;
			parameters[3].Value = model.standardLight1;
			parameters[4].Value = model.standardLight2;
			parameters[5].Value = model.standardLight3;
			parameters[6].Value = model.standardLight4;
			parameters[7].Value = model.standardLight5;
			parameters[8].Value = model.standardLight6;
			parameters[9].Value = model.standardLight7;
			parameters[10].Value = model.standardChrome1;
			parameters[11].Value = model.standardChrome2;
			parameters[12].Value = model.standardChrome3;
			parameters[13].Value = model.standardChrome4;
			parameters[14].Value = model.standardChrome5;
			parameters[15].Value = model.standardChrome6;
			parameters[16].Value = model.standardChrome7;
			parameters[17].Value = model.adjustLight1;
			parameters[18].Value = model.adjustLight2;
			parameters[19].Value = model.adjustChrome1;
			parameters[20].Value = model.adjustChrome2;
			parameters[21].Value = model.standardInfoID;
            parameters[22].Value = model.StandardDate;
			int rows=SQLiteHelper.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int standardInfoID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from StandardInfo ");
			strSql.Append(" where standardInfoID=@standardInfoID ");
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@standardInfoID", DbType.Int32,4)			};
			parameters[0].Value = standardInfoID;

			int rows=SQLiteHelper.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string standardInfoIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from StandardInfo ");
			strSql.Append(" where standardInfoID in ("+standardInfoIDlist + ")  ");
			int rows=SQLiteHelper.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Clipper.Model.StandardInfo GetModel(int standardInfoID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select standardInfoID,DetectItem,standardAmount,LightChromeRelativity,standardLight1,standardLight2,standardLight3,standardLight4,standardLight5,standardLight6,standardLight7,standardChrome1,standardChrome2,standardChrome3,standardChrome4,standardChrome5,standardChrome6,standardChrome7,adjustLight1,adjustLight2,adjustChrome1,adjustChrome2,StandardDate from StandardInfo ");
			strSql.Append(" where standardInfoID=@standardInfoID ");
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@standardInfoID", DbType.Int32,4)	};
			parameters[0].Value = standardInfoID;

			Clipper.Model.StandardInfo model=new Clipper.Model.StandardInfo();
			DataSet ds=SQLiteHelper.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Clipper.Model.StandardInfo DataRowToModel(DataRow row)
		{
			Clipper.Model.StandardInfo model=new Clipper.Model.StandardInfo();
			if (row != null)
			{
				if(row["standardInfoID"]!=null && row["standardInfoID"].ToString()!="")
				{
					model.standardInfoID=int.Parse(row["standardInfoID"].ToString());
				}
				if(row["DetectItem"]!=null)
				{
					model.DetectItem=row["DetectItem"].ToString();
				}
				if(row["standardAmount"]!=null && row["standardAmount"].ToString()!="")
				{
					model.standardAmount=int.Parse(row["standardAmount"].ToString());
				}
				if(row["LightChromeRelativity"]!=null && row["LightChromeRelativity"].ToString()!="")
				{
					model.LightChromeRelativity=int.Parse(row["LightChromeRelativity"].ToString());
				}
				if(row["standardLight1"]!=null && row["standardLight1"].ToString()!="")
				{
					model.standardLight1=decimal.Parse(row["standardLight1"].ToString());
				}
				if(row["standardLight2"]!=null && row["standardLight2"].ToString()!="")
				{
					model.standardLight2=decimal.Parse(row["standardLight2"].ToString());
				}
				if(row["standardLight3"]!=null && row["standardLight3"].ToString()!="")
				{
					model.standardLight3=decimal.Parse(row["standardLight3"].ToString());
				}
				if(row["standardLight4"]!=null && row["standardLight4"].ToString()!="")
				{
					model.standardLight4=decimal.Parse(row["standardLight4"].ToString());
				}
				if(row["standardLight5"]!=null && row["standardLight5"].ToString()!="")
				{
					model.standardLight5=decimal.Parse(row["standardLight5"].ToString());
				}
				if(row["standardLight6"]!=null && row["standardLight6"].ToString()!="")
				{
					model.standardLight6=decimal.Parse(row["standardLight6"].ToString());
				}
				if(row["standardLight7"]!=null && row["standardLight7"].ToString()!="")
				{
					model.standardLight7=decimal.Parse(row["standardLight7"].ToString());
				}
				if(row["standardChrome1"]!=null && row["standardChrome1"].ToString()!="")
				{
					model.standardChrome1=decimal.Parse(row["standardChrome1"].ToString());
				}
				if(row["standardChrome2"]!=null && row["standardChrome2"].ToString()!="")
				{
					model.standardChrome2=decimal.Parse(row["standardChrome2"].ToString());
				}
				if(row["standardChrome3"]!=null && row["standardChrome3"].ToString()!="")
				{
					model.standardChrome3=decimal.Parse(row["standardChrome3"].ToString());
				}
				if(row["standardChrome4"]!=null && row["standardChrome4"].ToString()!="")
				{
					model.standardChrome4=decimal.Parse(row["standardChrome4"].ToString());
				}
				if(row["standardChrome5"]!=null && row["standardChrome5"].ToString()!="")
				{
					model.standardChrome5=decimal.Parse(row["standardChrome5"].ToString());
				}
				if(row["standardChrome6"]!=null && row["standardChrome6"].ToString()!="")
				{
					model.standardChrome6=decimal.Parse(row["standardChrome6"].ToString());
				}
				if(row["standardChrome7"]!=null && row["standardChrome7"].ToString()!="")
				{
					model.standardChrome7=decimal.Parse(row["standardChrome7"].ToString());
				}
				if(row["adjustLight1"]!=null && row["adjustLight1"].ToString()!="")
				{
					model.adjustLight1=decimal.Parse(row["adjustLight1"].ToString());
				}
				if(row["adjustLight2"]!=null && row["adjustLight2"].ToString()!="")
				{
					model.adjustLight2=decimal.Parse(row["adjustLight2"].ToString());
				}
				if(row["adjustChrome1"]!=null && row["adjustChrome1"].ToString()!="")
				{
					model.adjustChrome1=decimal.Parse(row["adjustChrome1"].ToString());
				}
				if(row["adjustChrome2"]!=null && row["adjustChrome2"].ToString()!="")
				{
					model.adjustChrome2=decimal.Parse(row["adjustChrome2"].ToString());
				}
                if (row["StandardDate"].ToString() != "")
                {
                    model.StandardDate = DateTime.Parse(row["StandardDate"].ToString());
                }
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select standardInfoID,DetectItem,standardAmount,LightChromeRelativity,standardLight1,standardLight2,standardLight3,standardLight4,standardLight5,standardLight6,standardLight7,standardChrome1,standardChrome2,standardChrome3,standardChrome4,standardChrome5,standardChrome6,standardChrome7,adjustLight1,adjustLight2,adjustChrome1,adjustChrome2,StandardDate");
			strSql.Append(" FROM StandardInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return SQLiteHelper.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM StandardInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = SQLiteHelper.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.standardInfoID desc");
			}
			strSql.Append(")AS Row, T.*  from StandardInfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return SQLiteHelper.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@tblName", DbType.VarChar, 255),
					new SQLiteParameter("@fldName", DbType.VarChar, 255),
					new SQLiteParameter("@PageSize", DbType.Int32),
					new SQLiteParameter("@PageIndex", DbType.Int32),
					new SQLiteParameter("@IsReCount", DbType.bit),
					new SQLiteParameter("@OrderType", DbType.bit),
					new SQLiteParameter("@strWhere", DbType.VarChar,1000),
					};
			parameters[0].Value = "StandardInfo";
			parameters[1].Value = "standardInfoID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return SQLiteHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

